package com.ricky.constencrypt.api

object ConstEncrypt {
    interface IDecrypt {
        fun decrypt(value: String): String
    }

    private lateinit var mDecryptInterface: IDecrypt
    @JvmStatic
    fun init(decryptInterface: IDecrypt) {
        this.mDecryptInterface = decryptInterface
    }

    @JvmStatic
    fun decrypt(value: String): String {
        if (!::mDecryptInterface.isInitialized) {
            throw IllegalStateException("decrypt interface is null")
        }
        return mDecryptInterface.decrypt(value)
    }

    // 编译时会自动将调用这个方法的地方替换成ConstEncrypt.decrypt("编译时加密后的字符串")
    @JvmStatic
    fun wrap(value: String): String {
        return value
    }
}